from django.contrib import admin

# Register your models here.
from django.contrib import admin
from django.utils.translation import gettext_lazy as _
from . import models

from lib.django.admin import ImportExportFieldUseVerboseNameMixin, ModelAdmin
from unfold.contrib.import_export.forms import ImportForm, SelectableFieldsExportForm
from import_export.admin import ImportExportModelAdmin
from import_export import resources

class MediaResources(ImportExportFieldUseVerboseNameMixin, resources.ModelResource):
    class Meta:
        model = models.File

@admin.register(models.File)
class FileAdmin(ModelAdmin, ImportExportModelAdmin):
    resource_classes = [MediaResources]
    import_form_class = ImportForm
    export_form_class = SelectableFieldsExportForm
    
    permission_required = ['user.can_manage_resources']
    
    list_display = ['uuid', 'filename', 'content_type', 'file_size', 
                   'uploaded_at', 'owner', 'is_public']
    list_display_links = ['uuid', 'filename']
    list_select_related = ['owner', 'object_content_type']
    search_fields = ['filename', 'content_type']
    list_filter = ['is_public', 'object_content_type']
    raw_id_fields = ['owner']
    filter_horizontal = ['allowed_users']
